﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;

namespace IHISCETeim.Web.MachineSys.UserModel
{
    public partial class UQualityQuestionnaireReport : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "UQualityQuestionnaireReport";
            }
        }

        private DataTableCollection _reportDT = null;
        protected DataTableCollection reportDT
        { 
            get
            {
                if (_reportDT == null)
                {
                    _reportDT = UQualityQuestionnaireController.GetReport(CreateDateFrom, CreateDateTo);
                }
                return _reportDT;
            }
        
        }

        private string GetReprotNum(int UQTID)
        {

            DataRow[] drs  =reportDT[0].Select("UQTID=" + UQTID.ToString());
            return Convert.ToSingle(drs[0]["shownum"]).ToString("P");// +"&nbsp;" + drs[0]["macnum"].ToString() + "台";
        }
        #region 属性 (查询条件)


        protected bool ShowTimeInput
        {
            get
            {
                return GetRequestValue<bool>("ShowTimeInput", true);
            }
        }
        protected string CreateDateFrom
        {
            get
            {
                return ShowTimeInput ? "" : GetRequestValue<string>("CreateDateFrom", "");
            }
        }

        protected string CreateDateTo
        {
            get
            {
                string _temp = ShowTimeInput ? DateTime.Now.AddDays(1).ToString("yyyy-MM-dd") : GetRequestValue<string>("CreateDateTo", "");

                return CreateDateFrom.IsEmptyOrNull() ? "" : _temp.IsEmptyOrNull() ? Convert.ToDateTime(CreateDateFrom).AddDays(1).ToString("yyyy-MM-dd") : _temp;

                //  return _temp.IsEmptyOrNull() ? CreateDateFrom.IsEmptyOrNull() ? "" : Convert.ToDateTime(CreateDateFrom).AddDays(1).ToString("yyyy-MM-dd") :  CreateDateFrom.IsEmptyOrNull()?"":_temp;
            }
        }


        #endregion
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #region 获取调查表模板
        protected string GetUQuestionTemplete()
        {
            string TempHtml = "";
            //TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey);
            //if (!TempHtml.IsEmptyOrNull())
            //    return TempHtml;
            TempHtml = "";
            //  string ItemTmpHtmlTitleTemp = "<b>({0}){1}</b>";
            string ItemTmpHtmlConTemp = "<table>{0}</table> ";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0, 1);
            string trhtml = "";
            int tdnum = 0;
            trhtml = "<tr>";
            foreach (UQualityTempleteInfo item in allQtemp)
            {
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                if ((tdnum % 3) == 0 && tdnum != 0)
                {
                    trhtml = trhtml + "</tr><tr>";
                }
                trhtml = trhtml + string.Format("<td><b>{0}</b>", item.QTTitle);
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    string checkedstr = GetReprotNum(item2.UQTID);

                    trhtml = trhtml + string.Format("&nbsp;&nbsp;{0}({1})", item2.QTTitle, checkedstr);
                }
                trhtml = trhtml + "</td>";
                tdnum++;
            }
            trhtml = trhtml + "</tr>";

            ItemTmpHtmlConTemp = string.Format(ItemTmpHtmlConTemp, trhtml);
            TempHtml = ItemTmpHtmlConTemp;
            //UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey, TempHtml);
            return TempHtml;
        }

        protected string GetUQualityTemplete2()
        {
            string TempHtml = "";
            //TempHtml = UQualityQuestionnaireController.DC.Get<string>(DataCacheKey.UQualityTempleteDCKey2);
            //if (!TempHtml.IsEmptyOrNull())
            //    return TempHtml;
            TempHtml = "";
            string ItemTmpHtmlTitleTemp = "<b>{0}</b>";
            string ItemTmpHtmlConTemp = "<table >{0}</table>";
            List<UQualityTempleteInfo> allQtemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(0, 2);

            foreach (UQualityTempleteInfo item in allQtemp)
            {
                TempHtml = TempHtml + string.Format(ItemTmpHtmlTitleTemp, item.QTTitle);
                List<UQualityTempleteInfo> AllitemTemp = UQualityQuestionnaireController.UQualityTemplete_GetByParId(item.UQTID, item.QTType);
                string trhtml = "";
                int tdnum = 0;
                // item.RowTDNum = item.RowTDNum+1;
                trhtml = "<tr>";
                foreach (UQualityTempleteInfo item2 in AllitemTemp)
                {
                    if ((tdnum % item.RowTDNum) == 0 && tdnum != 0)
                    {
                        trhtml = trhtml + "</tr><tr>";
                    }
                    string checkedstr = GetReprotNum(item2.UQTID);
                    trhtml = trhtml + string.Format("<td>{0}({1})</td>", item2.QTTitle, checkedstr);
                    tdnum++;
                }
                trhtml = trhtml + "</tr>";

                TempHtml = TempHtml + string.Format(ItemTmpHtmlConTemp, trhtml);

            }
            // UQualityQuestionnaireController.DC.Add(DataCacheKey.UQualityTempleteDCKey2, TempHtml);
            return TempHtml;
        }
        #endregion
    }
}